package gpl.scotlandyard.detective.hint.main;

import gpl.androidcommons.scotlandyard.adapter.NodeMapAdapter;
import gpl.androidcommons.scotlandyard.listener.NodeShowLinksOnClickListener;
import gpl.scotlandyard.beans.basics.Node;
import gpl.scotlandyard.beans.basics.Player;
import gpl.scotlandyard.detective.hint.ApplicationManager;
import gpl.scotlandyard.detective.hint.R;

import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.LinearLayout;

public class MainFragment extends Fragment {

  public static final String ARG_MAP = "ARG_MAP";
  public static final String ARG_PLAYERS = "ARG_PLAYERS";

  private final List<Player> players;
  private final List<Node> map;

  @SuppressWarnings("unchecked")
  public MainFragment() {
    this.players = ApplicationManager.pull(ARG_PLAYERS, List.class);
    this.map = ApplicationManager.pull(ARG_MAP, List.class);
  }

  @Override
  public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final LinearLayout rootView = (LinearLayout) inflater.inflate(R.layout.main_fragment, container, false);

    GridView nodesGridView = (GridView) rootView.findViewById(R.id.gv_nodes);
    nodesGridView.setAdapter(new NodeMapAdapter(map, inflater));
    nodesGridView.setOnItemClickListener(new NodeShowLinksOnClickListener(getActivity()));
    return rootView;
  }
}
